package com.shakespace.artofandroid.chapter02.binderpool

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import com.shakespace.artofandroid.IBinderPool
import com.shakespace.artofandroid.global.Constants
import com.shakespace.firstlinecode.global.TAG

class BinderPoolService : Service() {


    private val binderPool = object : IBinderPool.Stub() {

        override fun queryBinder(binderCode: Int): IBinder? {
            return when (binderCode) {
                Constants.BINDER_COMPUTE -> ComputeImpl()
                Constants.BINDER_SECURITY_CENTER -> SecurityCenterImpl()
                else -> null
            }
        }
    }

    override fun onBind(intent: Intent): IBinder {
        return binderPool
    }

    override fun onCreate() {
        super.onCreate()
        Log.e(this.TAG, "onCreate: ")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e(this.TAG, "onDestroy: ")
    }
}
